package com.yiwu.common.domain.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yiwu.common.domain.dto.ChatMessageListDTO;
import com.yiwu.common.domain.entity.ChatMessage;

/**
 * @author 咏鹅
 * @description 针对表【Chat_message】的数据库操作Mapper
 * @createDate 2024-05-29 23:07:17
 * @Entity generator.domain.ChatMessage
 */
public interface ChatMessageMapper extends BaseMapper<ChatMessage> {

    Page<ChatMessageListDTO> getMessageList(Page<ChatMessageListDTO> page, Long userId);

    default Page<ChatMessage> selectPageMessageList(Long current, Long size, String sessionId, Long dateTime) {
        Page<ChatMessage> page = new Page<>(current, size);
        LambdaQueryWrapper<ChatMessage> wrapper = Wrappers.<ChatMessage>lambdaQuery()
                .eq(ChatMessage::getSessionId, sessionId)
                .eq(ChatMessage::getStatus,0)
                .le(ChatMessage::getSendTime, dateTime)
                .orderByAsc(ChatMessage::getSendTime);

        return selectPage(page, wrapper);
    }
}




